﻿using Fast.Application.Controllers._Test.Dtos;
using Fast.Application.Controllers._Test.Services;
using Fast.DynamicApiController.Dependencies;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Fast.Application.Controllers._Test
{
    /// <summary>
    /// 测试模块
    /// </summary>
    public class TestController: DynamicApiControllerBase
    {
        private readonly ITestService _test;

        public TestController(ITestService test)
        {
            _test = test;
        }

        /// <summary>
        /// 测试
        /// </summary>
        /// <param name="id">编号</param>
        /// <returns></returns>
        public string GetName(int id)
        {
            return _test.GetName();
        }

        [HttpGet]
        public string GetTest()
        {
            return _test.GetName();
        }

        // GET api/user
        [HttpGet]
        public List<string> GetAllUsers()
        {
            var users = new List<string> { "User1", "User2", "User3" };
            return users; // 返回 HTTP 200 OK 响应，数据是 JSON 格式
        }

        // GET api/user/5
        [HttpGet("{id}")]
        public IActionResult GetUserById(int id)
        {
            var user = $"User{id}";
            if (string.IsNullOrEmpty(user))
            {
                return NotFound(); // 返回 404 Not Found
            }
            return Ok(user); // 返回 200 OK 响应
        }

        // POST api/user
        [HttpPost]
        public IActionResult CreateUser([FromBody] string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                return BadRequest("Name cannot be empty"); // 返回 400 Bad Request
            }

            // 假设我们在这里创建了一个新用户
            return CreatedAtAction(nameof(GetUserById), new { id = 1 }, name); // 返回 201 Created
        }

        // PUT api/user/5
        public IActionResult UpdateUser(int id, [FromBody] string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                return BadRequest("Name cannot be empty");
            }

            // 假设我们在这里更新了用户信息
            return NoContent(); // 返回 204 No Content
        }

        // DELETE api/user/5
        public IActionResult DeleteUser(int id)
        {
            // 假设我们删除了用户
            return NoContent(); // 返回 204 No Content
        }
    }
}
